﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AffectsOtherPropertyAttribute.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the AffectsOtherPropertyAttribute type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Windows.Common
{
    using System;
    using System.Diagnostics.Contracts;

    /// <summary>
    /// Defines the <seealso cref="AffectsOtherPropertyAttribute"/> type.
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
    public sealed class AffectsOtherPropertyAttribute : Attribute
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AffectsOtherPropertyAttribute"/> class.
        /// </summary>
        /// <param name="otherPropertyName">Name of the other property.</param>
        public AffectsOtherPropertyAttribute(string otherPropertyName)
        {
            Contract.Requires<ArgumentNullException>(string.IsNullOrWhiteSpace(otherPropertyName) == false, "The other property name must not be null, empty or whitespace");
            AffectsProperty = otherPropertyName;
        }

        /// <summary>
        /// Gets the affects property.
        /// </summary>
        public string AffectsProperty { get; private set; }

        /// <summary>
        /// Objects the invariants.
        /// </summary>
        [ContractInvariantMethod]
        private void ObjectInvariants()
        {
            Contract.Invariant(string.IsNullOrWhiteSpace(AffectsProperty) == false, "The affected property name must never be null");
        }
    }
}